home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / AppleScript / Additions / ACME Script Widgets 1.0 / Tokenize ƒ / Tokenize READ ME < prev    next >
Encoding:
Text File  |  1994-11-02  |  4.4 KB  |  131 lines  |  [ttro/ttxt]

  1.  
  2. _________________________________________________
  3.  
  4.     Tokenize Scripting Addition ver. 1.1 
  5.  
  6.             Copyright (C) 1994 Wayne Walrath
  7.  
  8. _________________________________________________
  9.  
  10. This software is free for personal use. To obtain a cheap and simple license for
  11. corporate, commercial or institutional use, contact the author at one of the
  12. addresses listed at the end of this document. THIS SOFTWARE IS PROVIDED AS IS
  13. WITHOUT WARRANTIES. USE AT YOUR OWN RISK! You are encouraged to share this
  14. software with other people and to upload it to online services, but you may not
  15. charge money for it and you should only transfer the complete package. Contact
  16. me if you doubt whether you have a complete package. Inclusion on CD-ROMs
  17. requires explicit permission from me (the author).
  18.  
  19.  
  20. The demo AppleScript included with the distribution contains many examples of
  21. Tokenize's usage.
  22.  
  23. Tokenize was designed to make it easier to split text into elements based on a
  24. set of delimiters. The demo AppleScript illustrates several novel uses for
  25. Tokenize which may not be obvious at first glance.
  26.  
  27.  
  28. INSTALLATION:
  29. ______________________
  30. To install: Drag Tokenize to the Scripting Additions folder inside the
  31. Extensions folder.
  32.  
  33.  
  34.  
  35. BACKGROUND INFORMATION
  36. ______________________
  37.  
  38. Because of the way the tokenization is implemented, Tokenize can also be used
  39. as a quick way of removing unwanted characters from a text string. To better
  40. understand what is possible with Tokenize, here's a brief description of how
  41. Tokenize functions. The text to be tokenized is scanned for each of the strings
  42. given in the delimiter list, and all occurrences of these strings are replaced
  43. by a special character (essentially a null-char). After all delimiters are
  44. processed, a final pass is made which gathers all the strings between the
  45. special characters into a list. Understanding this algorithm will help you to
  46. figuring out how text will ultimately be parsed when using Tokenize.
  47.  
  48.  
  49. For example, consider an arbitrary string of text which contains words
  50. separated by tab characters, and between each word there will be one to three
  51. tabs. Here's a string set up as described:
  52.  
  53.     set testString to "One\tGiant\t\tStep\tFor\t\t\tMankind"
  54.  
  55.  
  56. If I tokenize this string using tab as the only delimiter, It returns this
  57. list:
  58.  
  59.     tokenize testString with delimiters tab
  60. => {"One", "Giant", "Step", "For", "Mankind"}
  61.  
  62.  
  63. If, on the other hand, I tokenize using a string of three tabs, the output is
  64. different:
  65.  
  66.     tokenize testString with delimiters tab & tab & tab
  67. =>    {"One    Giant        Step    For", "Mankind"}
  68.  
  69.  
  70. The output from this version consists of a list of two strings. Since tokenize
  71. only found one place in the testString where there were three tab characters
  72. side by side it split the string there. Tokenizing with a two tab string would
  73. produce yet a different result.
  74.  
  75.  
  76.  
  77. USAGE:
  78. ______________________
  79.  
  80. tokenize <a String> with delimiters { [<sep. string 1>] [,<sep. string2]...}
  81.  
  82. the direct parameter to tokenize is a string, and the second (required)
  83. parameter is a list of strings (one or more bytes in length) to use in
  84. tokenizing the direct parameter.
  85.  
  86. If you are only tokenizing with one delimiter you need not pass it as a list
  87. since AppleScript will handle the coercion for you. For example, the following
  88. is legal:
  89.  
  90. tokenize "My Name Is" with delimiters " Name "
  91. =>    {"My","Is"}
  92.  
  93.  
  94. Some text processing tasks require more than one call to Tokenize to perform.
  95. As an example, if the variable myText contained a number of lines separated by
  96. return characters, and you wanted to retrieve the words from line five, you
  97. could write the following AppleScript commands:
  98.  
  99. tokenize myText with delimiters {return} tokenize (item 5 of result) with
  100. delimiters {space}
  101. =>    [result is a list with all the words from line five of the text]
  102.  
  103.  
  104. ______________________
  105. Comments, bug reports and suggestions are welcomed. If you have any ideas for
  106. useful Scripting Additions which haven't been written yet, send me a message
  107. describing your idea.
  108.  
  109.  
  110. VERSION HISTORY:
  111. ______________________
  112. VER 1.1 - 2Nov94
  113. Fixed bug which surfaced in ver 1.0 when the tokens were longer than 255 chars.
  114. This bug resulted in random memory being stomped on when the token was too long.
  115. All users of version 1.0 should switch immediately.
  116.  
  117. Cleaned the code up a bit and optimized it a bit.
  118.  
  119. VER 1.0 - Oct94
  120. First release.
  121.  
  122.  
  123.     ___________________________
  124.         Wayne Walrath
  125.         2010 Ravenswood Dr.
  126.         Evansville, IN 47714
  127.         (812) 476-8610
  128.         walrath@cs.indiana.edu
  129.         CIS: 70233,3151 
  130.     ___________________________
  131.